﻿@namespace AntDesign
@inherits AntDomComponentBase

<CascadingValue Value="this" IsFixed>
    @if (ShowTooltip)
    {
        <Tooltip TitleTemplate="@content(this)" Placement="@Placement.Right" Disabled="TooltipDisabled">
            <Unbound Context="tooltip">
                @MenuItemContent(tooltip.Current)
            </Unbound>
        </Tooltip>
    }
    else
    {
        @MenuItemContent(Ref)
    }
</CascadingValue>

@code {

    RenderFragment MenuItemContent(ElementReference reference)
    {
        return @<li class="@ClassMapper.Class" role="menuitem" style="@PaddingStyle @Style" @onclick="HandleOnClick" @key="Key" @ref="reference">
        @icon(this)
        <span class="ant-menu-title-content">
            @if (RouterLink == null)
            {
                @content(this)
            }
            else
            {
                <MenuLink Href="@RouterLink" Match="@RouterMatch">@content(this)</MenuLink>
            }
        </span>
    </li>;
    }

  RenderFragment<MenuItem> content = item =>
  @<Template>
    @if (item.Title != null)
    {
        @item.Title
    }
    else
    {
      @item.ChildContent
    }
    </Template>
  ;

  RenderFragment<MenuItem> icon = item =>
  @<Template>
    @if (item.IconTemplate != null)
      {
        <span role="img" class=" anticon anticon-container">
          @item.IconTemplate
        </span>
      }
      else if (item.Icon != null)
      {
        <Icon Type="@item.Icon" />
      }
    </Template>
  ;
}